home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 25 / Cream of the Crop 25.iso / bbs / utilz20x.zip / HKEYS / HKEYS.CPP next >
C/C++ Source or Header  |  1997-04-13  |  5KB  |  154 lines

  1. /*
  2.  * This file is part of Utiliteez v1.00.R1
  3.  *
  4.  * Copyright (c) 1995, 1997 by Branislav L. Slantchev
  5.  * A fine product of Silicon Creations, Inc. (gargoyle)
  6.  *
  7.  * This program is free software; you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License as published by
  9.  * the Free Software Foundation; either version 2 of the License, or
  10.  * (at your option) any later version.
  11.  *
  12.  * This program is distributed in the hope that it will be useful,
  13.  * but without any warranty; without even the implied warranty of
  14.  * merchantability or fitness for a particular purpose. See the
  15.  * GNU General Public License for more details.
  16.  *
  17.  * You should have received a copy of the License along with this
  18.  * library, in the file LICENSE.DOC; if not, write to the address
  19.  * below to receive a copy via electronic mail.
  20.  *
  21.  * You can reach Branislav L. Slantchev (Silicon Creations, Inc.)
  22.  * at bslantch@cs.angelo.edu. The file SUPPORT.DOC has the current
  23.  * telephone numbers and the postal address for contacts.
  24. */
  25. #include "pblsdk.h"
  26. #include "file.h"
  27. #include "compiler.h"
  28. #include <string.h>
  29. #include <stdio.h>
  30. #include <stdlib.h>
  31.  
  32. #define PROGRAM_VERSION "v1.0"
  33.  
  34. void
  35. print_program_banner()
  36. {
  37.     printf("hKeys %s - Create ProBoard menu items with special hotkeys\n"
  38.            "   ■ Compiled on %s at %s\n"
  39.            "   ■ Copyright (c) by Branislav L. Slantchev /gargoyle\n"
  40.            "   ■ A product of Silicon Creations, Inc.\n\n",
  41.         PROGRAM_VERSION, __DATE__, __TIME__);
  42. }
  43.  
  44. void
  45. print_program_help()
  46. {
  47.     puts("Usage: hkeys <menu file(s)> -[return|escape]\n");
  48.     puts("    menu file: the name of the menu file(s) you want to process");
  49.     puts("    -return  : add an entry with 'enter' as the hotkey");
  50.     puts("    -escape  : add an entry with 'escape' as the hotkey\n");
  51.     puts("You can abbreviate -return to -r and -escape to -e");
  52.     puts("Wildcards can be used for the menu file specification");
  53.     puts("If you don't specify -return or -escape, none will be created");
  54.     puts("You can specify both -return and -escape in one command\n");
  55.     puts("Examples:");
  56.     puts("    hkeys global -escape   <- add escape item to the GLOBAL menu");
  57.     puts("    hkeys * -return        <- add return item to all menus");
  58.     puts("    hkeys top -r -e        <- add return and escape items to TOP\n");
  59. }
  60.  
  61. int
  62. make_spec(char *szMenuSpec, char *szWildcard)
  63. {
  64.     char    szFilePath[MAXPATH];
  65.     CONFIG  ConfigRec;
  66.     FILE   *fp;
  67.  
  68.     sprintf(szFilePath, "%s\\config.pro", getenv("PROBOARD"));
  69.     if( 0 == (fp = fopen(szFilePath, "rb")) ) return 0;
  70.     file_read(fp, &ConfigRec);
  71.     fclose(fp);
  72.     sprintf(szFilePath, "%s%s", ConfigRec.mnupath, file_name(szWildcard));
  73.     file_chext(szMenuSpec, szFilePath, ".pbm");
  74.     return 1;
  75. }
  76.  
  77. void
  78. create_hotkeys(char *pathSpec, Boolean bCreateEscape, Boolean bCreateReturn)
  79. {
  80.     zDosFile   ffblk;
  81.     int        done;
  82.     char       szBasePath[MAXPATH], szFileName[MAXPATH];
  83.     FILE      *fp;
  84.     MENU_ITEM  EscapeRec, ReturnRec;
  85.  
  86.     memset(&EscapeRec, 0, sizeof(EscapeRec));
  87.     memset(&ReturnRec, 0, sizeof(ReturnRec));
  88.  
  89.     strcpy(EscapeRec.text, "(escape) key item [generated by hKeys]");
  90.     strcpy(ReturnRec.text, "(return) key item [generated by hKeys]");
  91.     EscapeRec.color = ReturnRec.color = 15;
  92.     EscapeRec.hotkey = 033;
  93.     ReturnRec.hotkey = 015;
  94.     memset(&EscapeRec.timeFrame, 0xff, sizeof(TimeFrame));
  95.     memset(&ReturnRec.timeFrame, 0xff, sizeof(TimeFrame));
  96.  
  97.     strcpy(szBasePath, file_dirspec(pathSpec));
  98.     done = FindFirst(pathSpec, 0, &ffblk);
  99.     while( !done ){
  100.         printf("Processing %s ", ffblk.name);
  101.         if( bCreateEscape ) printf("(escape) ");
  102.         if( bCreateReturn ) printf("(return) ");
  103.         printf("... ");
  104.  
  105.         sprintf(szFileName, "%s%s", szBasePath, ffblk.name);
  106.         if( 0 == (fp = fopen(szFileName, "r+b")) ){
  107.             printf("file not found: '%s'\n", szFileName);
  108.         }
  109.         else{
  110.             fseek(fp, 0L, SEEK_END);
  111.             if( bCreateEscape ) file_write(fp, &EscapeRec);
  112.             if( bCreateReturn ) file_write(fp, &ReturnRec);
  113.             printf("updated\n");
  114.             fclose(fp);
  115.         }
  116.  
  117.         done = FindNext(&ffblk);
  118.     }
  119. }
  120.  
  121. int
  122. main(int argc, char *argv[])
  123. {
  124.     char    pathSpec[MAXPATH];
  125.     Boolean bCreateReturn = False;
  126.     Boolean bCreateEscape = False;
  127.  
  128.     print_program_banner();
  129.     if( 2 > argc ){
  130.         print_program_help();
  131.         return 1;
  132.     }
  133.     if( !make_spec(pathSpec, argv[1]) ){
  134.         puts("hkeys: unable to construct menu specification (aborting)");
  135.         return 1;
  136.     }
  137.     for( int i = 2; i < argc; ++i ){
  138.         switch( argv[i][1] ){
  139.             case 'e': case 'E': bCreateEscape = True; break;
  140.             case 'r': case 'R': bCreateReturn = True; break;
  141.             default :
  142.                 printf("hkeys: unknown option: '%s'\n", argv[i]);
  143.                 return 1;
  144.         }
  145.     }
  146.     if( !bCreateEscape && !bCreateReturn ){
  147.         print_program_help();
  148.         puts("hkeys: nothing to do!");
  149.         return 1;
  150.     }
  151.     create_hotkeys(pathSpec, bCreateEscape, bCreateReturn);
  152.     return 0;
  153. }
  154.